import Vue from 'vue';
import VueRouter from "vue-router";
const Home = () => import('../views/home/Home');
const ProFile = () => import('../views/profile/PriFile');
const Category = () => import('../views/category/Category');
const Cart = () => import('../views/cart/Cart');
const Detail = () => import('views/detail/Detail');

Vue.use(VueRouter);

/*重写push的方法(解决两次相同的push会报错)*/
const routerPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(error=> error)
};

const routes = [
  {
    path: '/Detail/:id',
    component: Detail,
    children: [
      {
        path: 'Detail/:id',
        component: Detail
      }
    ]
  },
  {
    path: '/Cart',
    component: Cart
  },
  {
    path: '/Category',
    component: Category
  },
  {
    path: '/ProFile',
    component: ProFile
  },
  {
    path: '/Home',
    component: Home
  },
  {
    path: '/',
    redirect: '/Home'
  }
];

const router = new VueRouter({
  routes,
  mode: 'history'
});

export default router;
